package cn.edu.tju.se.auth.controller;

import cn.edu.tju.se.auth.enity.Customer;
import cn.edu.tju.se.auth.enity.Goods;
import cn.edu.tju.se.auth.enity.Store;
import cn.edu.tju.se.auth.repository.AdminRepository;
import cn.edu.tju.se.auth.service.CustomService;
import cn.edu.tju.se.auth.service.GoodsService;
import cn.edu.tju.se.auth.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "admin")
public class AdminController {

    @Autowired
    private AdminRepository adminRepository;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private StoreService storeService;

    @Autowired
    private CustomService customService;


//    @PostMapping(path = "addAdmin")
//    public void addAdmin(@RequestBody Administrator administrator){
//        adminRepository.save(administrator);
//    }
//
//    @DeleteMapping(path = "deleteAdmin")
//    public void deleteAdmin(@RequestBody Administrator administrator){
//        adminRepository.delete(administrator);
//    }
//
//    @GetMapping(path = "getAllAdmins")
//    public List<?> getAllAdmin(){
//        return adminRepository.findAll();
//    }
//
//    @GetMapping(path = "getAdmin")
//    public List<?> getAdmin(String adminname){
//        return adminRepository.findByadminname(adminname);
//    }

    @PostMapping(path = "deleteGoods")
    public void deleteGoods(@RequestBody Goods goods){
        //管理员强制下架商品
        goodsService.deleteGoods(goods);
    }

    @DeleteMapping(path = "deleteGoods")
    public void deleteStore(@RequestBody Store store){
        //管理员强制封印店家(*^▽^*)
        storeService.deleteStore(store);
    }

    @GetMapping(path = "getAllStores")
    public List<?> getAllStores(){
        //管理员查看所有在注册商家
        return storeService.getAllStores();
    }

    @GetMapping(path = "getAllCustoms")
    public List<?> getAllCustomes(){
        //管理员查看所有在注册用户
        return customService.getAllCustomers();
    }

    @DeleteMapping(path = "deleteCustomer")
    public void deleteCustomer(@RequestBody Customer customer){
        //管理员强制注销用户
        customService.deleteCustomer(customer);
    }

    @GetMapping(path = "getGoods")
    public List<?> getGoods(@RequestParam String store){
        //管理员查看某店铺的全部货物
        return goodsService.findBystorename(store);
    }

    @PostMapping(path = "updateGoods")
   public void updateGoods(@RequestBody Goods goods){
        //强行修改商品信息
        goodsService.addGoods(goods);
    }

}
